package cn.itsource.controller;

import cn.itsource.constants.SmsContants;
import cn.itsource.service.ISmsService;
import cn.itsource.util.AjaxResult;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private ISmsService smsService;
    //1 以下两个放到常量类中
    //Uid=本站用户名
    //Key=接口安全秘钥
    //2 以下两个是动态传入
    // smsMob=手机号码&smsText=验证码:8888
    @PostMapping
    AjaxResult send(@RequestParam String params){
        System.out.println(params);
        Map<String,String> paramsTmp =
                JSONObject.parseObject(params, Map.class);
        //封装参数
        paramsTmp.put("Uid", SmsContants.SMS_UID);
        paramsTmp.put("Key", SmsContants.SMS_KEY);
        return smsService.sendSmsCode(paramsTmp);
    }
}
